home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Appls / test / thand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-14  |  1.0 KB  |  67 lines  |  [TEXT/????]

  1. /* Test wungetevent from signal handler */
  2.  
  3. #include "stdwin.h"
  4. #include <signal.h>
  5.  
  6. #define SPECIAL 1000
  7.  
  8. TEXTEDIT *tb;
  9.  
  10. void
  11. drawproc(win, l, t, r, b)
  12.     WINDOW *win;
  13. {
  14.     tedraw(tb);
  15. }
  16.  
  17. int
  18. handler() {
  19.     EVENT e;
  20.     e.type= WE_COMMAND;
  21.     e.u.command= SPECIAL;
  22.     wungetevent(&e);
  23. }
  24.  
  25. main(argc, argv)
  26.     int argc;
  27.     char **argv;
  28. {
  29.     WINDOW *win;
  30.     int width, height;
  31.     
  32.     winit();
  33.     signal(SIGINT, handler);
  34.     if (argc >= 3) {
  35.         int h= atoi(argv[1]), v= atoi(argv[2]);
  36.         wsetdefwinpos(h, v);
  37.     }
  38.     
  39.     win= wopen("Textedit", drawproc);
  40.     wgetwinsize(win, &width, &height);
  41.     wsetdocsize(win, width, height);
  42.     
  43.     tb= tealloc(win, 0, 0, width);
  44.     tereplace(tb, "Hello, world\n--Guido van Rossum");
  45.     
  46.     for (;;) {
  47.         EVENT e;
  48.         wgetevent(&e);
  49.         if (e.type == WE_CLOSE)
  50.             break;
  51.         if (e.type == WE_COMMAND) {
  52.             if (e.u.command == WC_CLOSE ||
  53.                 e.u.command == WC_CANCEL)
  54.                 break;
  55.             else if (e.u.command == SPECIAL) {
  56.                 wmessage("Got event from handler");
  57.                 continue;
  58.             }
  59.         }
  60.         (void) teevent(tb, &e);
  61.     }
  62.     tefree(tb);
  63.     wclose(win);
  64.     wdone();
  65.     exit(0);
  66. }
  67.